#include "Transaction.hh"
#include <sstream>

namespace minibank {

// Default constructor
Transaction::Transaction()
    : id(""), type(TransactionType::Deposit), amount(0.0), note(""), targetAccountId("") {}

// Copy constructor
Transaction::Transaction(const Transaction& other)
    : id(other.id), type(other.type), amount(other.amount),
      note(other.note), targetAccountId(other.targetAccountId) {}

// Copy assignment operator
Transaction& Transaction::operator=(const Transaction& other) {
    if (this != &other) {
        id = other.id;
        type = other.type;
        amount = other.amount;
        note = other.note;
        targetAccountId = other.targetAccountId;
    }
    return *this;
}

// Destructor
Transaction::~Transaction() = default;

// Parameterized constructor
Transaction::Transaction(const std::string& id_, TransactionType type_, double amount_,
                         const std::string& note_, const std::string& target_)
    : id(id_), type(type_), amount(amount_), note(note_), targetAccountId(target_) {}

// Convert to string
std::string Transaction::toString() const {
    std::ostringstream oss;
    oss << "[" << id << "] ";
    switch (type) {
        case TransactionType::Deposit: oss << "Deposit ¥" << amount; break;
        case TransactionType::Withdraw: oss << "Withdraw ¥" << amount; break;
        case TransactionType::Transfer: oss << "Transfer ¥" << amount
                                            << " to " << targetAccountId; break;
    }
    if (!note.empty()) {
        oss << " (" << note << ")";
    }
    return oss.str();
}

} // namespace minibank